﻿using IdentityModel;
using IdentityServer4.Models;
using IdentityServer4.Validation;
using System.Security.Claims;

namespace IdentityServer
{
    public class ResourceOwnerPasswordValidator : IResourceOwnerPasswordValidator
    {
        public ResourceOwnerPasswordValidator()
        {
        }

        public async Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {

            if (context.UserName == "admin" && context.Password == "admin")
            {
                 context.Result = new GrantValidationResult(
                 subject: "lhr123456.",
                 authenticationMethod: OidcConstants.AuthenticationMethods.Password
                 );
            }
            else
                //验证失败
                context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "invalid custom credential");
        }
 
    }
}
